#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, u[800005], v[800005], c[800005];
struct Edge {
	int to, w, id;
};
vector<Edge> edges[800006];
namespace CR200J {
	int sum[5005][25], ansn[50005]; // ansn 表示需要横穿整个子树的 F 总值。
	void dfs(int i, int fa) {
		memset(sum[i], 0, sizeof(sum[i]));
		ansn[i] = 0;
		sum[i][21] = 1;
		for (auto j : edges[i]) {
			if (j.to == fa) continue;
			dfs(j.to, i);
			int sumj[23] = {};
			for (int x = 1; x <= 21; ++x) sumj[min(x, j.w)] += sum[j.to][x];
			for (int x = 1; x <= 21; ++x) {
				for (int y = 1; y <= 21; ++y) {
					if (x == y && y == 21) continue;
					ansn[i] += min(x, y) * sum[i][x] * sumj[y];
				}
			}
			for (int x = 1; x <= 20; ++x) sum[i][x] += sumj[x];
			sum[i][21] = 1;	
		}
	}
	void main() {
/*		dfs(1, 0);
		for (int j = 1; j <= n; ++j) {
			for (int x = 1; x <= 21; ++x) cout << sum[j][x] << " \n"[x == 21];
			cout << ansn[j] << "\n";
		}
		return;*/
		for (int i = 1; i < n; ++i) {
			dfs(u[i], v[i]);
			dfs(v[i], u[i]);
			int ans = 0;
			for (int j = 1; j <= n; ++j) ans += ansn[j];
			cout << ans << "\n";
		}
	}
}

namespace CR400AF {
	int sum[800005][25], sumj[800005][23], ansn[800005], res[800005], dep[800005];
	void dfs(int i, int fa) {
		dep[i] = dep[fa] + 1;
		for (auto j : edges[i]) {
			if (j.to == fa) continue;
			dfs(j.to, i);
			sum[i][j.w]++;
			for (int x = 1; x <= 20; ++x) sum[i][min(x, j.w)] += sum[j.to][x];
		}
		for (int x = 1; x <= 20; ++x) ansn[i] += x * sum[i][x];
	}
	void dfs2(int i, int fa) {
		for (auto j : edges[i]) {
			if (j.to == fa) continue;
			for (int x = 1; x <= 20; ++x) sumj[j.to][min(x, j.w)] += sumj[i][x] + sum[i][x] - sum[j.to][x];
			dfs2(j.to, i);
		}
		for (int x = 1; x <= 20; ++x) res[i] += x * sumj[i][x];
	}
	void main() {
		dfs(1, 0);
		dfs2(1, 0);
		int all = 0;
		for (int i = 1; i <= n; ++i) {
			all += res[i] + ansn[i];
		}
		all /= 2;
		for (int i = 1; i < n; ++i) {
			if (dep[u[i]] > dep[v[i]]) swap(u[i], v[i]);
			int sums = all - res[v[i]];
			for (int x = 1; x <= 20; ++x) {
				for (int y = 1; y <= 20; ++y) {
					sums -= min(x, y) * sumj[v[i]][x] * sum[v[i]][y];
				}
			}
			cout << sums << "\n";
		}
	}
}

signed main() {
	freopen("tatooine.in", "r", stdin); freopen("tatooine.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;

	for (int i = 1; i < n; ++i) {
		cin >> u[i] >> v[i] >> c[i];
		edges[u[i]].push_back({v[i], c[i], i});
		edges[v[i]].push_back({u[i], c[i], i});
	}
	if (n <= 500 && 0) {
		CR200J::main();
	} else {
		CR400AF::main();
	}
	return 0;
}
